<template>
  <el-select size="small" v-model="cValue" :placeholder="placeholder" :multiple="multiple">
    <el-option v-for="item in cOptions" :key="item.codeValue" :label="item.codeName" :value="item.codeValue"></el-option>
  </el-select>
</template>

<script>
import { querySysCode } from '@/api/sys/sys-code'

export default {
  name: 'CcSelectSc',
  props: {
    type: {
      type: String,
      required: true
    },
    value: [String, Array],
    multiple: {
      type: Boolean,
      default: false
    },
    placeholder: String
  },
  methods: {
    querySysCode () {
      querySysCode({
        condition: [
          { property: 'codeType', value: this.type, type: 'EQ' },
          { property: 'status', value: '0', type: 'EQ' }
        ],
        sort: [
          { property: 'orderNo', direction: 'ASC' }
        ]
      }).then(response => {
        if (response.data.success === true && response.data.statusCode === 200) {
          this.cOptions = response.data.data.records
        } else {
          this.$message({ type: 'error', message: response.data })
        }
      })
    }
  },
  watch: {
    value (val, oldVal) {
      this.cValue = this.value
    },
    cValue (val, oldVal) {
      this.$emit('input', this.cValue)
    }
  },
  data () {
    return {
      cValue: [String, Array],
      cOptions: Array
    }
  },
  mounted () {
    this.cValue = this.value
    this.querySysCode()
  }
}
</script>
